<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

<h:head></h:head>
<body>
	<f:metadata>
		<f:viewParam name="i" value="#{publicBean.invitationLink}" />
		<f:viewAction action="#{publicBean.checkLink}" />
	</f:metadata>

	<h:form id="form" rendered="#{empty publicBean.error}">
	<p:contextMenu for="rooms" widgetVar="cMenu">     
        	<p:menuitem value="Edit Cell" icon="ui-icon-search" onclick="PF('roomsTable').showCellEditor();return false;"/>    
        	<p:menuitem value="Hide Menu" icon="ui-icon-close" onclick="PF('cMenu').hide()"/>    
    	</p:contextMenu>
		<p:panelGrid>
			<p:row>
				<p:column>
					<p:panelGrid style="width: 100%" cellpadding="3" id="meanPanel">
						<f:facet name="header">
							<p:row>
								<p:column colspan="2">
									<p:outputLabel value="Transport mean" />
								</p:column>
							</p:row>
						</f:facet>
						<p:row>
							<p:column colspan="2">
								<p:outputLabel id="meanName"
									value="#{publicBean.reservation.mean.name}" />
							</p:column>
						</p:row>

						<p:row>
							<p:column>
								<p:outputLabel for="meanPrice" value="Prezzo: " />
							</p:column>
							<p:column>
								<p:outputLabel id="meanPrice"
									value="#{publicBean.reservation.mean.price}" />
							</p:column>
						</p:row>
						<p:row>
							<p:column>
								<p:outputLabel for="meanDeparture" value="Partenza: " />
							</p:column>
							<p:column>
								<p:outputLabel
									value="#{publicBean.reservation.mean.departure.name}"
									id="meanDeparture" />
							</p:column>
						</p:row>
						<p:row>
							<p:column>
								<p:outputLabel for="meanQuantity" value="Booking for: " />
							</p:column>
							<p:column>
								<p:outputLabel id="meanQuantity"
									value="#{publicBean.reservation.travellers}" />
							</p:column>
						</p:row>
					</p:panelGrid>
				</p:column>
				<p:column>
					<p:panelGrid columns="2" cellpadding="3" id="hotelPanel"
						width="100%">
						<f:facet name="header">
							<p:row>
								<p:column colspan="2">
									<p:outputLabel value="Hotel" />
								</p:column>
							</p:row>
						</f:facet>
						<p:row>
							<p:column rowspan="2">
								<p:outputLabel id="hotelName"
									value="#{publicBean.reservation.hotel.name}" />
							</p:column>
						</p:row>
						<p:dataTable id="rooms" var="r"
							value="#{publicBean.rooms}" editable="true"
							editMode="cell" widgetVar="roomsTable">

							<p:column headerText="Room type">
								<p:outputLabel value="#{r.type.toString()}" />
							</p:column>

							<p:column headerText="Hotel rooms">
								<p:outputLabel value="#{r.totalRooms}" />
							</p:column>

							<p:column headerText="Price">
								<p:outputLabel value="#{r.price}" />
							</p:column>

							<p:column headerText="Your needs">
								<p:cellEditor>
									<f:facet name="output">
										<h:outputText value="#{r.selectedRooms}" />
									</f:facet>
									<f:facet name="input">
										<p:inputText id="valueInput" value="#{r.selectedRooms}"
											style="width:96%" />
									</f:facet>
								</p:cellEditor>
							</p:column>
						</p:dataTable>
					</p:panelGrid>
				</p:column>
			</p:row>
			<p:row>
				<p:column>
					<p:dataList style="width: 100%" styleClass="borderLess"
						id="excursionList" value="#{publicBean.reservation.excursions}"
						var="ex" itemType="circle">
						<f:facet name="header">
							<p:outputLabel value="Excursions" />
						</f:facet>
	    	#{ex.name}, #{ex.weekDay.toString()} 
			</p:dataList>
				</p:column>
				<p:column>
					<p:outputLabel value="How many travellers?" />
					<p:inputText size="5" value="#{publicBean.reservation.travellers}"
						id="travellers">
						<f:validator validatorId="numberValidator" />
					</p:inputText>
					<p:outputLabel
						value="Total price per person: #{publicBean.currentPrice.toPlainString()} €" />
				</p:column>
			</p:row>

			<p:row>
				<p:column colspan="2">
					<p:commandButton style="align: center" value="Join reservation"
						update=":form :message" action="#{publicBean.join()}" />
					<h:message for="travellers" style="align: right; color: red" />
				</p:column>
			</p:row>
		</p:panelGrid>
	</h:form>
	<p:outputLabel id="message" value="#{publicBean.message}" style="color: red" />
	<p:outputLabel id="error" rendered="#{not empty publicBean.error}"
		value="#{publicBean.error}" style="color: red" />
</body>
</html>
